package com.sundi.ecmarket.service.impl;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.mapper.Wrapper;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.sundi.ecmarket.config.ExcelBean;
import com.sundi.ecmarket.config.ExcelUtils;
import com.sundi.ecmarket.dto.BrandDto;
import com.sundi.ecmarket.dto.IssueDto;
import com.sundi.ecmarket.entity.EcBrand;
import com.sundi.ecmarket.entity.EcIssue;
import com.sundi.ecmarket.mapper.EcBrandMapper;
import com.sundi.ecmarket.service.IEcBrandService;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import org.apache.commons.lang3.StringUtils;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.springframework.stereotype.Service;

import java.beans.IntrospectionException;
import java.lang.reflect.InvocationTargetException;
import java.text.ParseException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * <p>
 * 品牌商表 服务实现类
 * </p>
 *
 * @author Mht
 * @since 2020-02-23
 */
@Service
public class EcBrandServiceImpl extends ServiceImpl<EcBrandMapper, EcBrand> implements IEcBrandService {


    @Override
    public List<EcBrand> selectBrandList(BrandDto brandDto) {
        return this.baseMapper.selectBrandList(brandDto);
    }

    @Override
    public void updateLogicDel(Integer id) {

        this.baseMapper.updateLogicDel(id);
    }

    @Override
    public XSSFWorkbook downLoadGoodsExcel(BrandDto brandDto) throws Exception {
        PageHelper.startPage(brandDto.getPageNo(),brandDto.getPageSize());
        Wrapper wrapper = new EntityWrapper();

        if (StringUtils.isNotBlank(brandDto.getName())){
            wrapper.like("name",brandDto.getName());
        }
        List<EcBrand> list = this.selectList(wrapper);
        PageInfo<EcBrand> pageInfo = new PageInfo(list);
        Map<Integer,List<ExcelBean>> map = new HashMap<Integer,List<ExcelBean>>();
        List<ExcelBean> excelBeans = new ArrayList<>();
        excelBeans.add(new ExcelBean("id","id",0));
        excelBeans.add(new ExcelBean("品牌商名称","name",0));
        excelBeans.add(new ExcelBean("品牌商简介","desc",0));
        excelBeans.add(new ExcelBean("品牌商页的品牌商图片","pic_url",0));
        excelBeans.add(new ExcelBean("排名","sort_order",0));
        excelBeans.add(new ExcelBean("品牌商的商品低价，仅用于页面展示","floor_price",0));
        map.put(0,excelBeans);

        return ExcelUtils.createExcelFile(EcBrand.class,pageInfo.getList(),map,"商铺列表");
    }
}
